import {
  pageCourseLsit
} from '@/api/manage/teacher.js'
import {
  get_img_src
} from '@/utils/index.js'
import CourseSection from '@/components/Course/CourseSection/index.vue'
export default {
  components: {
    CourseSection
  },
  data() {
    return {
      learningPhaseId: '',
      learningPhases: [],
      grades: [],
      subjects: [],
      versions: [],
      volumes: [],
      listParam: {
        learningPhaseId: '',
        courseGradeId: '',
        courseSubjectId: '',
        courseVersionId: '',
        courseVolumeId: ''
      },
      courseDatas: [],
      listPages: {
        layout: 'total, sizes, prev, pager, next, jumper', // 分页显示参数
        page: 1, // 当前所在分页数
        size: 5, // 每页显示的条目数
        // sizes: [1, 2, 3, 4, 5, 10, 15, 20], // 每页显示的条目数设置
        sizes: [5, 10, 15, 20], // 每页显示的条目数设置
        total: 478, // 总条数
        count: 5, // 总页数=总条数/每页条目
        counter: 7, // 页码按钮的数量，当总页数超过该值时会折叠
        prevtext: '上一页',
        nexttext: '下一页',
        single: false
      }
    }
  },
  created() {
    this.pageCourseLsit()
  },
  watch: {
    $route: {
      handler() {
        this.listParam = {
          learningPhaseId: this.$route.query.learningPhaseId || null,
          courseGradeId: this.$route.query.courseGradeId || null,
          courseSubjectId: this.$route.query.courseSubjectId || null,
          courseVersionId: this.$route.query.courseVersionId || null,
          courseVolumeId: this.$route.query.courseVolumeId || null
        }
      },
      deep: true
    },
    listParam: {
      handler() {
        this.pageCourseLsit()
      },
      deep: true
    }
  },
  methods: {
    pageCourseLsit() { /** 查询课程列表 */
      this.listParam.page = this.listPages.page
      this.listParam.size = this.listPages.size
      this.loadObj = this.$loading({
        lock: true,
        text: '加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      pageCourseLsit(this.listParam).then(response => {
        this.listPages.total = response.total
        this.courseDatas = response.data
        // console.log(this.courseDatas)
        this.loadObj.close()
      })
    },
    clickTo(item) {
      this.$router.push({
        path: 'step1',
        query: {
          courseId: item.courseId,
          courseName: item.courseName,
          courseGradeId: item.courseGradeId,
          courseGradeName: item.courseGradeName
        }
      })
    },
    page_size_change(size) {
      this.listPages.size = size
      this.pageCourseLsit()
    },
    page_current_change(page) {
      this.listPages.page = page
      this.pageCourseLsit()
    },
    page_prev_click() {
      this.listPages.page--
      this.pageCourseLsit()
    },
    page_next_click() {
      this.listPages.page++
      this.pageCourseLsit()
    },
    get_img_src(val) { /** 获取文件路径 */
      return get_img_src(val)
    }
  }
}
